// 字符串首字母大写
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)

capitalize("hello world")  // Hello world

// 翻转字符串
const reverse = str => str.split('').reverse().join('');

reverse('hello world'); 

// 随机字符串
const randomString = () => Math.random().toString(36).slice(2);

randomString();

// 截断字符串
const truncateString = (string, length) => string.length < length ? string : `${string.slice(0, length - 3)}...`;

truncateString('Hi, I should be truncated because I am too loooong!', 36)   // 'Hi, I should be truncated because...'

// 去除字符串中的HTML
const stripHtml = html => (new DOMParser().parseFromString(html, 'text/html')).body.textContent || '';
